import time

import win32com.client
from selenium import webdriver
from selenium.webdriver.common.by import By
from automatic.tools.file_upload import FileUpload
from automatic import page

#启动浏览器
driver=webdriver.Edge()

#全屏浏览器
driver.maximize_window()

#登录的页面名称
url='http://120.204.73.73:8034/operator/task'
driver.get(url)

#隐式等待
driver.implicitly_wait(5)
time.sleep(2)

# #网页标题
# print(driver.title)
# #当前地址
# print(driver.current_url)
# #浏览器名称
# print(driver.name)
# #页面源码
# print(driver.page_source)

# def base_find_element(value,timeout=30,poll_frequency=0.5):
#     return driver.find_element(value)

#定位元素
element=driver.find_element(By.ID,'username')
element.clear()
element.send_keys('root')
time.sleep(1)

element=driver.find_element(By.ID,'password')
element.clear()
element.send_keys('123456')
time.sleep(1)

codetext=driver.find_element(By.CLASS_NAME,'code').text
element=driver.find_element(By.ID,'inputCode')
element.clear()
element.send_keys(codetext)
time.sleep(1)

#点击登录
element=driver.find_element(By.XPATH,'//*[@id="root"]/div/div/div/div/div[2]/form/button')
element.click()
time.sleep(2)


#登录成功后点击新建任务
driver.find_element(By.XPATH,'//*[@id="root"]/div/div/div[2]/div[2]/main/div/div/div/div/div/div[2]/div[1]/a/button').click()
time.sleep(2)

driver.find_element(By.ID,'title').send_keys('作文标注')
driver.find_element(By.ID,'description').send_keys('对ai生成的作文进行标注')
time.sleep(2)

driver.find_element(By.CSS_SELECTOR,'.ant-btn.css-170tjox.ant-btn-primary.ant-btn-color-primary.ant-btn-variant-solid.ml-4').click()
time.sleep(2)

driver.find_element(By.CSS_SELECTOR,'.ant-btn.css-170tjox.ant-btn-link.ant-btn-color-primary.ant-btn-variant-link').click()
time.sleep(2)

#对弹出的窗口进行定位
driver.find_element(By.CLASS_NAME,'text-primary').click()
time.sleep(2)#防止窗口弹出缓慢，进行强制等待
# sr=win32com.client.Dispatch('WScript.shell')
# time.sleep(2)
# sr.SendKeys('E:\\word\\1.json\r\n')
# time.sleep(2)
FileUpload.upload_file(page.task_filepath)

#文件上传完成后点击确定
driver.find_element(By.XPATH,"//button[@class='ant-btn css-170tjox ant-btn-primary ant-btn-color-primary ant-btn-variant-solid']").click()
time.sleep(2)

js='window.scrollTo(0,document.body.scrollHeight);'
driver.execute_script(js)
time.sleep(2)

#点击创建
# driver.find_element(By.XPATH,'//*[@id="root"]/div/div/div[2]/div[2]/main/div/div/div/div/div/div[2]/div[2]/form/div[6]/div/div/div/div/button[1]').click()
# time.sleep(3)


#关闭浏览器
driver.close()
